Imports System.Web.UI.clientscriptmanager

Partial Class TopBar
    Inherits System.Web.UI.UserControl

    Private _pv As New PageView

    Protected Sub publishPage()

        traverseControlTree(Page.Controls)

    End Sub

    Private Sub traverseControlTree(ByVal cc As ControlCollection)

        For Each c As Control In cc

            If TypeOf c Is ContentArea Then

                Dim ca As ContentArea = DirectCast(c, ContentArea)
                ca.RemotePublish()

            End If

            traverseControlTree(c.Controls)

        Next c

    End Sub

    Protected Sub btnPublish_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnPublish.Click
        publishPage()
    End Sub

    Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLogout.Click
        _pv.EndSession()
        Response.Redirect("~/default.aspx")
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

        Me.Visible = False

        If Not _pv.UserName Is Nothing Then
            Me.Visible = True
        End If

    End Sub
End Class
